home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / PMOUSE0.ASM next >
Encoding:
Assembly Source File  |  1993-05-10  |  9.1 KB  |  180 lines

  1. ;***********************************************************************
  2. ;  Program PMouse0 ( Chapter 10 )
  3. ;
  4. ;  The demo program for mouse (Graphics Mode)
  5. ;
  6. ;  Author:  A.I.Sopin, Voronezh University. 1993
  7. ;
  8. ;  The interrupt 33h (mouse service) is used
  9. ;
  10. ;  The mouse driver reqired
  11. ;
  12. ;***********************************************************************
  13.     EXTRN   INSYM4 : FAR
  14.     .MODEL  SMALL
  15.     .STACK
  16. ;----------------------------------------------------------
  17.     .DATA
  18. BELL    EQU     07      ;  sound signal
  19. LF      EQU     10      ;  Line Feed
  20. CR      EQU     13      ;  Carriage Return
  21. TEXT0   DB      " The MOUSE demo program  (INT 33h). "
  22.     DB      "  Press any key to continue...", BELL, CR, LF, "$"
  23. TEXT1   DB      " The mouse driver is not installed !!!."
  24.     DB      "  Press any key...", BELL, CR, LF, "$"
  25. TEXT2   DB      " An active mouse driver found."
  26.     DB      "  Press any key...", BELL, CR, LF, "$"
  27. TXT0    DB      " Function 0 - initialize mouse."
  28.     DB      "  Press any key...", BELL, "$"
  29. TXT1    DB      CR, " Function 1 - show mouse cursor."
  30.     DB      "  Press any key...", BELL, "$"
  31. TXT2    DB      CR, " Function 2 - hide mouse cursor."
  32.     DB      "  Press any key...", BELL, "$"
  33. TXT3    DB      CR, " Function 3 - press mouse key.   (Enter -Exit).        "
  34.     DB      BELL, CR, LF, "$"
  35. TXT3L   DB      CR, " Left button pressed.   CODE=0X."
  36.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  37. TXT3R   DB      CR, " Right button pressed.  CODE=0X."
  38.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  39. TXT3M   DB      CR, " Middle buttom pressed. CODE=0X."
  40.     DB      " COL=XXXX. ROW=XXXX.", BELL, "$"
  41. TXT9    DB      CR, " Function 9 - define graphics cursor.  Press any key..."
  42.     DB      BELL, CR, LF, "$"
  43. ;  SCREEN MASK FOR POINTING HAND
  44. PtrHand       LABEL   WORD
  45.     DW      0E1FFh, 0E1FFh, 0E1FFh, 0E1FFh, 0E1FFh, 0, 0, 0
  46.     DW      0, 0, 0, 0, 0, 0, 0, 0,
  47. ;  CURSOR MASK FOR POINTING HAND
  48.     DW      01E00h, 01200h, 01200h, 01200h
  49.     DW      01200h, 013FFh, 01249h, 01249h
  50.     DW      0F249h, 09001h, 09001h, 09001h
  51.     DW      08001h, 08001h, 08001h, 0FFFFh
  52. VMODE   DB      3        
  53. CX0     DW      0
  54. DX0     DW      0
  55. ;----------------------------------------------------------
  56.     .CODE
  57. OutMsg  macro   Txt
  58.     lea     dx,Txt                  ;  addres of message
  59.     mov     ah,09h                  ;  function 09h - output text string
  60.     int     21h                     ;  DOS  service call
  61.     endm
  62. WaitKey macro
  63.     mov     ah,0                    ;  function 0 - wait for key pressed
  64.     int     16h                     ;  BIOS keyboard service
  65.     endm
  66. ;-------------------------------------------------------------------
  67. .STARTUP
  68.     mov     ah,0Fh                  ;  function 0Fh - get video mode
  69.     int     10h                     ;  BIOS video service call
  70.     mov     VMODE,al                ;  save current video mode
  71.     mov     ah,0                    ;  function 0 - set video mode
  72.     mov     al,10h                  ;  640x350  graphic (EGA, VGA)
  73.     int     10h                     ;  BIOS video service call
  74. ;       Output initial message
  75.     OutMsg  TEXT0                   ;  output initial message
  76.     WaitKey
  77. ;  check for mouse driver present
  78.     mov     ax, 03533h              ;  function 35h - get interrupt vector
  79.     int     21h                     ;  DOS service call
  80.     mov     ax,es                   ;  segment address of handler
  81.     or      ax,bx                   ;  AX - segment .OR. offset of int 33
  82.     jz      Nomouse                 ;  if full addres is 0 - no mouse
  83.     mov     bl,es:[bx]              ;  get first instrucyion of handler
  84.     cmp     bl,0CFh                 ;  is this IRET instruction?
  85.     jne     Begin                   ;  if not - driver installed
  86. Nomouse:OutMsg  TEXT1                   ;  output message "driver not found"
  87.     WaitKey                         ;  wait for key pressed
  88.     jmp     Exit                    ;  Exit program
  89. ;-------------------------------------------------------------------
  90. Begin:  OutMsg  TEXT2                   ;  output message "driver installed"
  91.     WaitKey                         ;  wait for key pressed
  92. ;-------------------------------------------------------------------
  93. ;  Initialize mouse and report status (function 0 of INT 33h)
  94. Func0:  OutMsg  TXT0                    ;  output message "function 0"
  95.     WaitKey
  96.     xor     ax,ax                   ;  Initialize mouse
  97.     int     33h                     ;  mouse service call
  98.     cmp     ax,0                    ;  is mouse installed?
  99.     jnz     Func1                   ;  if so, pass to function 1
  100.     jz      Exit                    ;  if not, exit program
  101. ;-------------------------------------------------------------------
  102. ;  Function 1 - show the mouse cursor
  103. Func1:  OutMsg  TXT1                    ;  output message "function 1"
  104.     mov     ax,1                    ;  function 01 - show mouse cursor
  105.     int     33h                     ;  mouse service call
  106.     WaitKey
  107. ;-------------------------------------------------------------------
  108. ;  Function 2 - hide cursor
  109. Func2:  OutMsg  TXT2                    ;  output message "function 2"
  110.     mov     ax,2                    ;  function 02 - hide mouse cursor
  111.     int     33h                     ;  mouse service call
  112.     WaitKey
  113. ;-------------------------------------------------------------------
  114. ;  Function 09 - set new graphic cursor
  115. Func9:  OutMsg  TXT9                    ;  output message "function 9"
  116.     Waitkey
  117.     mov     ax,09h                  ;  function 09 - Define Graphics Cursor
  118.     mov     bx,0                    ;  column of cursor hot spot in bitmap
  119.     mov     cx,0                    ;  row of cursor hot spot in bitmat
  120.     push    ds                      ;
  121.     pop     es                      ;  ES now points to Data Segment
  122.     lea     dx,PtrHand              ;  ES:DX - address of cursor bitmap
  123.     int     33h                     ;  mouse service call
  124.     mov     ax,1                    ;  function 01 - show mouse cursor
  125.     int     33h                     ;  mouse service call
  126. ;-------------------------------------------------------------------
  127. ;  Function 3 - deterrmine the keys state and the button pressed
  128. Func3:  OutMsg  TXT3                    ;  output message "function 3"
  129. ChkKBD: mov     ah,1                    ;  function 01h - check keyboard buffer
  130.     int     16h                     ;  BIOS keyboard service
  131.     jz      ContF3                  ;  if no key pressed, continue
  132.     jmp     Exit                    ;  exit if key pressed
  133. ;  determining mouse keys pressed
  134. ContF3: mov     ax,3                    ;  func. 03 - button status and location
  135.     int     33h                     ;  mouse service call
  136.     mov     CX0,cx                  ;  save  X coordinate (column)
  137.     mov     DX0,dx                  ;  save  Y coordinate (row)
  138.     test    bx,1                    ;  left button pressed?
  139.     jnz     M3L                     ;
  140.     test    bx,2                    ;  right button pressed?
  141.     jnz     M3R                     ;
  142.     test    bx,4                    ;  middle button pressed ?
  143.     jnz     M3M                     ;
  144.     jmp     short ChkKBD            ;  no button pressed - check again
  145. M3L:    lea     dx,TXT3L                ;  address of message "left button"
  146.     jmp     short   M3MES           ;  to output message
  147. M3R:    lea     dx,TXT3R                ;  address of message "right button"
  148.     jmp     short   M3MES           ;  to output message
  149. M3M:    lea     dx,TXT3M                ;  address of message "miiddle button"
  150. ;  Output number and code of mouse key pressed
  151. M3MES:  or      bl,30h                  ;  convert key number into ASCII code
  152.     mov     di,dx                   ;  address of message into DI
  153.     mov     ds:[di+31],bl           ;  place ASCII code of key pressed
  154.     push    dx                      ;  save address of message
  155.     mov     si,4                    ;  lehgth of variable to be edited
  156.     lea     bp,[di+38]              ;  address for placing edited text
  157.     xor     dx,dx                   ;  high part of number to be edited
  158.     mov     ax,CX0                  ;  low part is column
  159.     Call    INSYM4                  ;  convert number in DX:AX to string
  160.     mov     si,4                    ;  lehgth of variable to be edited
  161.     lea     bp,[di+48]              ;  address for placing edited text
  162.     xor     dx,dx                   ;  high part of number to be edited
  163.     mov     ax,DX0                  ;  low part is row
  164.     Call    INSYM4                  ;  convert number in DX:AX to string
  165. ;  output cursor coordinates and key code
  166.     pop     dx                      ;  address of text buffer
  167.     mov     ah,9                    ;  Output message to screen
  168.     int     21h                     ;  DOS service call
  169.     jmp     ChkKBD                  ;  check whether key was pressed
  170. ;-------------------------------------------------------------------
  171. ;  Terminate program and exit to DOS
  172. Exit:   mov     ah,0                    ;  function 00h - set video mode
  173.     mov     al,VMODE                ;  original video mode
  174.     int     10h                     ;  BIOS video service call
  175.     mov     ax,0C00h                ;  function 0Ch - flush keyboard buffer
  176.     int     21h                     ;  DOS service call
  177.     mov     ax,4C00h                ;  function 4Ch - terminate process
  178.     int     21h                     ;  DOS service call
  179.     END
  180.